package com.stephen.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by stephen on 2021-03-28 14:14 .
 * Description: servlet转发,新地址不需要加上下文路径
 */
public class DispatherDemo extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = this.getServletContext();
        // path为转发到的目的地址,forward是传递参数
        context.getRequestDispatcher("/geta").forward(req,resp);
    }
}
